package com.danger.Util;

import android.graphics.Bitmap;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by danger on 2016/3/29.
 */
public class ImageSaveAsFile {

    public static String saveFile(Bitmap bm, String fileName, String upload_path) throws IOException {
        Bitmap bitmap = ImageCompress.compress(bm);
        int index = upload_path.lastIndexOf("/");
        String path = upload_path.substring(0, index + 1);
        File dirFile = new File(path);
        if (!dirFile.exists()) {
            dirFile.mkdir();
        }
        File myCaptureFile = new File(path + fileName);
        BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myCaptureFile));
        bitmap.compress(Bitmap.CompressFormat.JPEG, 80, bos);
        bos.flush();
        bos.close();
        return path + fileName;
    }
}
